<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<chiptrack:checkLogon sourcePage="/salesOrder.do"/>
<%
    User user1 = (User) session.getAttribute (SessionKeys.USER_KEY);
    String chipTracContext = "/" + ConfigManager.getChipTracContext();
    int i=0;
    String selectedMethod = null;
    String selectedAccount = null;
    com.scalar.chiptrack.sales.forms.SalesOrderForm salesOrderForm1 = null;
    int isSample = 1;

%>
<%@ page import="java.util.ArrayList,
				com.scalar.chiptrack.utils.ConfigManager,
				com.scalar.chiptrack.commons.SessionKeys,
                com.scalar.chiptrack.commons.Constants,
				com.scalar.chiptrack.users.User,
				com.scalar.chiptrack.users.Functionality,
                com.scalar.chiptrack.utils.StringUtils,
                com.scalar.chiptrack.sales.forms.SalesOrderForm,
                java.util.HashMap,
                com.scalar.chiptrack.sales.ContactPerson,com.scalar.chiptrack.sales.CustomerPartNumber,
                com.scalar.chiptrack.sales.SalesOrder, com.scalar.chiptrack.sales.LineItem" %>
<%@ page import="com.scalar.chiptrack.sales.actions.ChangeOrderAction" %>
<HTML>
<HEAD>
<TITLE>Scalarsoft -ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/sales_order.js"></script>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/Product.js"></script>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/sales_common.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/quickSearch.js"></script>
<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" onload='check();init();'>
<script language="JavaScript">
    function init()
    {
        if ( document.salesOrderForm["manufacturingPartNo"] != null )
        {
            var partNo = document.salesOrderForm["manufacturingPartNo"];
            var x = eval(document.salesOrderForm["manufacturingPartNo"]);
            if (x.name == 'manufacturingPartNo')
            {
                qs_1 = new QuickSearch(partNo, document.salesOrderForm["qs1"], false);
            }
            else
            {
                for(var i=0; i <partNo.length; i++)
                {
                    var tmp = 'qs_'+(i+1)+' = new QuickSearch(partNo['+i+'], document.salesOrderForm["qs'+(i+1)+'"], false)';
                    eval(tmp);
                }
            }    
        }
    }
    var isSample = 1;
    function check()
    {
        var pa1=document.getElementById("newshippingMethod");
        var pa3=document.getElementById("newshippingAccount");
        <% salesOrderForm1 = (SalesOrderForm)request.getAttribute("salesOrderForm"); %>
        document.salesOrderForm.shippingAddressId.value=<%=salesOrderForm1.getShippingAddressId()%>;
        document.salesOrderForm.billingAddressId.value=<%=salesOrderForm1.getBillingAddressId()%>;
        isSample = <%=request.getParameter("isSample")%>
        <%
        String addShipMethod = request.getParameter("shipAccount1");
        if( addShipMethod == null || ( !addShipMethod.equals( "-2" ) ) )
        {
        %>
        document.salesOrderForm.newshippingMethod.style.visibility = "hidden";
        pa1.innerHTML = "";
        document.salesOrderForm.newshippingAccount.style.visibility = "hidden";
        pa3.innerHTML = "";
        <%
        }
        if( ( addShipMethod != null ) && ( !addShipMethod.trim().equals( "" ) ) )
        {
        %>
        document.salesOrderForm.shippingMethod.value = '<%=addShipMethod%>';
        if ( document.salesOrderForm.shippingMethod.value == "" )
        {
            document.salesOrderForm.shippingMethod.value = "-1";
        }
        document.salesOrderForm.shipAccount1.value = '<%=addShipMethod%>';
        <%
        }
        %>
        var salesTaxType = document.salesOrderForm.salesTaxType.value;
        <%
        String state1 = request.getParameter ( "newSalesState" );
        String value1 = request.getParameter ( "newSalesTax" );
        if( state1 != null && value1 != null )
        {
        %>
            if ( salesTaxType == "-1" )
            {
                addNewSalesTaxType( document.salesOrderForm.salesTaxType );
                document.salesOrderForm.newSalesState.value = '<%=state1%>';
                document.salesOrderForm.newSalesTax.value = '<%=value1%>';
            }
        <% }  %>
        var shippingLabel = document.getElementById("newShippingTerms");
        var letterOfCreditNoObj = document.getElementById("letterOfCreditNo");
        var lcIssuingBankObj    = document.getElementById("lcIssuingBank");

		if( document.salesOrderForm.shippingTerms.value == -2 )
		{
			document.salesOrderForm.newShippingTerms.style.visibility = "visible";
			shippingLabel.innerHTML = "New Pay Terms : ";
		}
		else
		{
			document.salesOrderForm.newShippingTerms.style.visibility = "hidden";
			shippingLabel.innerHTML = "";
		}
        var deliveryTermsLabel = document.getElementById("newDeliveryTerms");
		if( document.salesOrderForm.deliveryTerms.value == -2 )
		{
			document.salesOrderForm.newDeliveryTerms.style.visibility = "visible";
			deliveryTermsLabel.innerHTML = "New <bean:message key="label.sales.salesOrder.DeliveryTerms" /> : ";
		}
		else
		{
			document.salesOrderForm.newDeliveryTerms.style.visibility = "hidden";
			deliveryTermsLabel.innerHTML = "";
		}
        var pa = document.getElementById("shippingInstructions");
        if ( document.salesOrderForm.shippingInstructionsId.value == -2 )
        {
            pa.innerHTML = "New <bean:message key="label.sales.shippingInstructions" />";
            document.salesOrderForm.shippingInstructions.readOnly = false;
        }
        else
        {
            pa.innerHTML = "<bean:message key="label.sales.shippingInstructions" />";
            document.salesOrderForm.shippingInstructions.readOnly = true;
        }
        if( document.salesOrderForm.contactPerson.value == '' )
        {
             document.salesOrderForm.contactPerson.value = '';
             document.salesOrderForm.phoneNumber.value = '';
             document.salesOrderForm.cellNumber.value = '';
             document.salesOrderForm.faxNumber.value = '';
             document.salesOrderForm.email.value = '';

             document.salesOrderForm.phoneNumber.disabled = true;
             document.salesOrderForm.cellNumber.disabled = true;
             document.salesOrderForm.faxNumber.disabled = true;
             document.salesOrderForm.email.disabled = true;
        }
        if ( isSample == 0 )
        {
            var price = document.salesOrderForm["unitPriceAsDouble"];
            var zeroPrice = document.salesOrderForm["zeroPrice"];
            var expediteFee = document.salesOrderForm["expediteFee"];

            if( price.length == null )
            {
                var element2 = eval( "document.salesOrderForm.expediteFee" + (document.salesOrderForm.jsLineItemNo.value) );
                element2.disabled = true;
            }
            else
            {
                for ( var i = 0; i < price.length; i++ )
                {
                    var element2 = eval( "document.salesOrderForm.expediteFee" + (document.salesOrderForm.jsLineItemNo[i].value) );
                    element2.disabled = true;
                }
            }
        }
        showHideNewEndUserField();
        var form = document.salesOrderForm;
        var endCustomerCtrl = form.odmId;
        var newEndCustomerNameCtrl = form.newEndCustomerName;
        var endCustomerLabelSpan = document.getElementById ( "endCustomerLabelSpan" );
        var endCustomerTxfieldSpan = document.getElementById ( "endCustomerTxfieldSpan" );
        if ( endCustomerCtrl.value == "-2" )
        {
            endCustomerLabelSpan.style.display = 'block';
            endCustomerTxfieldSpan.style.display = 'block';
        }
        else
        {
            newEndCustomerNameCtrl.value = "";
            endCustomerLabelSpan.style.display = 'none';
            endCustomerTxfieldSpan.style.display = 'none';
        }
        showHideNewCustPartNo(-1);
    }


</script>

<SCRIPT language="JavaScript">
var prevPrice = 0;
<%
    HashMap  salesOrderMap = ( HashMap ) session.getAttribute( "salesOrderMap" );
    SalesOrder salesOrderFromMap = null;
    if ( salesOrderMap != null )
    {
        salesOrderFromMap = (SalesOrder)( salesOrderMap.get( salesOrderForm1.getCustomerId()+"" ));
        pageContext.setAttribute( "billingAddressContactPersons", salesOrderFromMap.getContactPersonsForBillingAddress() );
        pageContext.setAttribute( "shippingAddressContactPersons", salesOrderFromMap.getContactPersonsForShippingAddress() );
        pageContext.setAttribute( "shippingAddresses", salesOrderFromMap.getShippingAddresses () );
        pageContext.setAttribute( "billingAddresses", salesOrderFromMap.getBillingAddresses () );
        pageContext.setAttribute( "contactPersons", salesOrderFromMap.getContactPersons () );
        pageContext.setAttribute( "salesPersons", salesOrderFromMap.getSalesPersons() );
        pageContext.setAttribute( "salesReps", salesOrderFromMap.getSalesReps() );
        pageContext.setAttribute( "odmList", salesOrderFromMap.getOdmList() );
        pageContext.setAttribute( "endCustomerList", salesOrderFromMap.getEndCustomerList() );

       ArrayList lineItemsList = (ArrayList) request.getAttribute ( "lineItems" );
       if ( lineItemsList == null )
       { lineItemsList = (ArrayList) session.getAttribute ( "lineItems" );}
       ArrayList customerPartNumbers = null;
       try{
           java.util.HashMap mapCustPartNos = salesOrderFromMap.getMfgPartsWithCustomerPartNos() ;
           for (int j = 0; j < lineItemsList.size(); j++) {
                LineItem lineItem = (LineItem) lineItemsList.get(j);
                customerPartNumbers = new ArrayList();
                if ( lineItem.getManufacturingPartNo() != null && lineItem.getManufacturingPartNo().trim().length() > 0)
                {
                    customerPartNumbers = (ArrayList)mapCustPartNos.get(lineItem.getManufacturingPartNo());
                }
                request.setAttribute( "customerPartNumbers"+lineItem.getLineItemNo(),  customerPartNumbers);
           }
       }
      catch(Exception ex) {
          System.out.println(ex);
          ex.printStackTrace();
      }
    }
    HashMap contactPersonsList = salesOrderFromMap.getCustomerContactPersonMap();
    if( contactPersonsList != null )
    {
        int listSize = contactPersonsList.size();
        java.util.Iterator contactPersonsIterator = contactPersonsList.keySet().iterator();
        ContactPerson contactPersons[] = new ContactPerson[listSize];
        %>
            var customerContactPerson = new Array(<%=listSize%>);
            var customerPhNo          = new Array(<%=listSize%>);
            var customerCellNo        = new Array(<%=listSize%>);
            var customerFax           = new Array(<%=listSize%>);
            var customerEmail         = new Array(<%=listSize%>);
            customerContactPerson[-3] = '';
            customerContactPerson[-2] = -1;
            customerContactPerson[-1] = '';
        <%
        for( int aa = 0; aa < listSize ; aa++)
        {
           Object key = (String)contactPersonsIterator.next();
           if( contactPersonsList.get(key)!= null )
            {
                if(contactPersonsList.containsKey(key))
                {
                    contactPersons[aa] = (ContactPerson)contactPersonsList.get(key);
                    %>
                        customerContactPerson[<%=aa%>] = '<%=contactPersons[aa].getContactPerson().replaceAll("'","\\\\" + "'")%>';
                        customerPhNo[<%=aa%>]          = '<%=contactPersons[aa].getPhoneNumber().replaceAll("'","\\\\" + "'")%>';
                        customerCellNo[<%=aa%>]        = '<%=contactPersons[aa].getCellNumber().replaceAll("'","\\\\" + "'")%>';
                        customerFax[<%=aa%>]           = '<%=contactPersons[aa].getFaxNumber().replaceAll("'","\\\\" + "'")%>';
                        customerEmail[<%=aa%>]         = '<%=contactPersons[aa].getEmail()%>';
                    <%
               }
           }
       }
   }

    HashMap billAddressList = salesOrderFromMap.getBillingAddressMap();
    if(billAddressList != null)
    {
        int billListSize = billAddressList.size();
        java.util.Iterator billContactPersonsIterator = billAddressList.keySet().iterator();
        String billAddresses[] = new String[billListSize];
        %>
            var billContactPerson = new Array(<%=billListSize%>);
            var billAddress       = new Array(<%=billListSize%>);
            billContactPerson[-3] = '';
            billContactPerson[-2] = -1;
            billContactPerson[-1] = '';
        <%
        for( int bb = 0; bb < billListSize ; bb++)
        {
           Object key = (String)billContactPersonsIterator.next();
           if( billAddressList.get(key)!= null )
            {
                if(billAddressList.containsKey(key))
                {
                    billAddresses[bb] = (String)billAddressList.get(key);
                    %>
                        billContactPerson[<%=bb%>] = '<%=key.toString().replaceAll("'","\\\\" + "'")%>';
                        billAddress[<%=bb%>]          = "<%=(billAddresses[bb].toString()).replace('\n','~').replaceAll("'","\\\\" + "'")%>";

                    <%
               }
           }
       }
   }
    HashMap shipAddressList = salesOrderFromMap.getShippingAddressMap();
    if(shipAddressList != null)
    {
        int shipListSize = shipAddressList.size();
        java.util.Iterator shipContactPersonsIterator = shipAddressList.keySet().iterator();
        String shipAddresses[] = new String[shipListSize];
        %>
            var shipContactPerson = new Array(<%=shipListSize%>);
            var shipAddress       = new Array(<%=shipListSize%>);
            shipContactPerson[-3] = '';
            shipContactPerson[-2] = -1;
            shipContactPerson[-1] = '';
        <%
        for( int bb = 0; bb < shipListSize ; bb++)
        {
           Object key = (String)shipContactPersonsIterator.next();
           if( shipAddressList.get(key)!= null )
            {
                if(shipAddressList.containsKey(key))
                {
                    shipAddresses[bb] = (String)shipAddressList.get(key);
                    %>
                        shipContactPerson[<%=bb%>] = '<%=key.toString().replaceAll("'","\\\\" + "'")%>';
                        shipAddress[<%=bb%>]          = '<%=(shipAddresses[bb].toString()).replace('\n','~').replaceAll("'","\\\\" + "'")%>';


                    <%
               }
           }
       }
   }
    ArrayList shipArr = salesOrderFromMap.getShippingMethods ();
    int size1 =0;
    if(shipArr !=  null)
    {
        size1 = shipArr.size();
    }
%>
    var shppingLables = new Array(<%=size1%>);
    var shppingValues = new Array(<%=size1%>);
<%
    if( shipArr != null)
    {
%>
        shppingLables[-2] = '';
        shppingLables[-1] = '';
<%
        for(int s = 0 ; s < shipArr.size() ; s++)
        {
%>
            shppingLables[<%=s%>] = '<%=((org.apache.struts.util.LabelValueBean)shipArr.get(s)).getLabel().replaceAll("'","\\\\" + "'")%>';
            shppingValues[<%=s%>] ='<%=((org.apache.struts.util.LabelValueBean)shipArr.get(s)).getValue().replaceAll("'","\\\\" + "'")%>';
<%
        }
%>
        shppingLables[<%=size1%>] = -2 ;
<%
   }
%>
    if (document.layers)
    {
        window.setResizable(false);
    }
    var count = <%= (String)session.getAttribute("maxLineItemNo") %>;
    var errors  = "";
	var errors1 = "";
    var dateElement = "";
    function openCalendar(dateValue)
    {
        dateElement = dateValue;
        newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','calenderPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
        newWindow.moveTo(550,180);
        newWindow.focus();
    }

    function assignDate(passedValue)
    {
        dateElement.value=passedValue;
        window.focus();
    }
    function addTextArea()
    {
        var tab = document.getElementById ("lineItemsTable");
        var index = document.getElementById ("rowIndex").rowIndex;
        var newRow = tab.insertRow ( index );
        var newCell = newRow.insertCell();
        newCell.style.backgroundColor = "#DEE1E2";
        var htmltext = '<input type="text" name="lineItemNo" value="'+count+'" size=6 class="txfield" disabled="true">';
        htmltext = htmltext + '<input type="hidden" name="lineItemNo" value="'+count+'">';
        htmltext = htmltext + '<input type="hidden" name="jsLineItemNo" value="'+count+'">';
        newCell.innerHTML = htmltext;

        newCell = newRow.insertCell();
        newCell.style.backgroundColor = "#DEE1E2";
        htmltext = '<input type="text" name="poLineItemNo" value="'+count+'" size=6 class="txfield" disabled="true">';
        htmltext = htmltext + '<input type="hidden" name="poLineItemNo" value="'+count+'">';
        newCell.innerHTML = htmltext;

        newCell = newRow.insertCell();
        newCell.style.backgroundColor = "#DEE1E2";

        htmltext = '&nbsp;<script language="javascript" defer="defer"> qs_'+count+' = new QuickSearch(document.salesOrderForm.manufacturingPartNo['+(count-1)+'],  document.salesOrderForm["qs'+count+'"], false );<'+'/'+'script>';
        htmltext = htmltext +'<input type="text" name="qs'+count+'" class="txfield" size="35" onkeyup="quickSearch(qs_'+count+')"/><br>';
        htmltext = htmltext + '<select name="manufacturingPartNo" class="txfield" onchange="getComments('+(count-1)+');';
        <% if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_MARKETING_PART_NUMBER)) { %>
            htmltext= htmltext +'showMktgPartNumber('+(count-1)+');';
        <% } %>
        htmltext= htmltext + '"><option value="" >Select Part Number</option>';

        <%
        java.util.ArrayList optionlist = null;
        java.util.ArrayList mfgList = null;
        org.apache.struts.util.LabelValueBean option = null;
        CustomerPartNumber customerPartNo = new  CustomerPartNumber();
        StringBuffer strBuffer = null;
        StringBuffer strBuffer1 = null;
        int mfgListsize =0;
		try
		{
			mfgList = salesOrderFromMap.getMfgParts();
			if( mfgList == null)  mfgList =  new java.util.ArrayList();
			mfgListsize = mfgList.size();
			strBuffer1 = new StringBuffer();
			for( int j = 0; j < mfgListsize; j++)
			{
				customerPartNo = (CustomerPartNumber)mfgList.get(j);
				strBuffer1.append("htmltext = htmltext + '");
				strBuffer1.append("<option value=\"").append(customerPartNo.getManufacturingPartNo()).append("\">");
				strBuffer1.append(customerPartNo.getManufacturingPartNo()).append("</option>';\n");
			}
			out.println(strBuffer1);
		}
        catch(Exception ex)
        {
			System.out.println(ex);
        }
        %>
        htmltext = htmltext + '</select>';

        newCell.innerHTML = htmltext;

        <% if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_MARKETING_PART_NUMBER)) { %>
            newCell = newRow.insertCell ();
            newCell.style.backgroundColor = "#DEE1E2";
            htmltext = '<span class="NArialL" id="marketingPartNoSpan'+(count-1)+'"></span>';
            newCell.innerHTML = htmltext;
         <% } %>


        newCell = newRow.insertCell();
        newCell.style.backgroundColor = "#DEE1E2";
        htmltext = '<select name="customerPartNo"  class="txfield" onchange="showHideNewCustPartNo(' + (count-1)+ ')"><option value="">Select Customer Part No</option><option value="-2">--Add New CustomerPart No--</option></select><input type="text" name="newCustomerPartNo" maxlength="50" size="20" value="" style="display:none;" class="txfield">';
        newCell.innerHTML = htmltext;
        newCell = newRow.insertCell();
        newCell.style.backgroundColor = "#DEE1E2";
        newCell.noWrap = true;
        htmltext = '<textarea name="lineItemDescription" class="txfield" onkeydown="javascript:setTextAreaMaxLength(this,200)" onkeyup="javascript:setTextAreaMaxLength(this,200)" ></textarea>';
        newCell.innerHTML = htmltext;

        newCell = newRow.insertCell();
        newCell.style.backgroundColor = "#DEE1E2";
        newCell.style.textAlign = "center";
        <% if((request.getParameter("isSample") != null) && (request.getParameter("isSample").equals("0"))) { %>
            htmltext = '<input type=checkbox name="isTaxable'+count+'" disabled="true">';
        <% } else { %>
            htmltext = '<input type=checkbox name="isTaxable'+count+'" >';
        <% }%>
        newCell.innerHTML = htmltext;

        newCell = newRow.insertCell();
        newCell.style.backgroundColor = "#DEE1E2";
        newCell.noWrap = true;
        htmltext = '<input type="text" name="requestDate" size=12 class="txfield">';
        htmltext = htmltext + '&nbsp;<a href="javascript:if(document.salesOrderForm.requestDate.length!=null){openCalendar(document.salesOrderForm.requestDate['+(count-1)+'])}else{openCalendar(document.salesOrderForm.requestDate)}"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></img></a>';
        newCell.innerHTML = htmltext;

        newCell = newRow.insertCell();
        newCell.style.backgroundColor = "#DEE1E2";
        htmltext = '<input type="text" name="quantity" size=8 class="valuetxfield" value="0" onkeypress="javascript:allowInteger()" onblur="javascript:checkBaseOrderQty('+(count-1)+')" maxlength="6">';
        htmltext = htmltext + '<input type="hidden" name="oldQty" value="0">';
        newCell.innerHTML = htmltext;

        newCell = newRow.insertCell();
        newCell.style.backgroundColor = "#DEE1E2";
        if ( isSample == 0 )
        {
            htmltext = '<input type="text" name="unitPriceAsDouble" size=12 class="valuetxfield" value="0.0" onkeypress="javascript:restrictCharacters(this,7,<%=ConfigManager.getnoOfDecmalsInAmount()%>)" onkeyup="javascript:restrictAmt(this,7,<%=ConfigManager.getnoOfDecmalsInAmount()%>)" >';
        }
        else
        {
            htmltext = '<input type="text" name="unitPriceAsDouble" size=12 class="valuetxfield" value="0.0" onkeypress="javascript:restrictCharacters(this,7,<%=ConfigManager.getnoOfDecmalsInAmount()%>)" onkeyup="javascript:restrictAmt(this,7,<%=ConfigManager.getnoOfDecmalsInAmount()%>)" ></td>';
        }
        newCell.innerHTML = htmltext;

        newCell = newRow.insertCell();
        newCell.style.backgroundColor = "#DEE1E2";
        htmltext = '<input type="text" name="amount" size=25 class="valuetxfield" value="$0.00" disabled="true">';
        newCell.innerHTML = htmltext;

        newCell = newRow.insertCell();
        newCell.style.backgroundColor = "#DEE1E2";
        newCell.style.textAlign = "center";
        if ( isSample == 0 )
        {
            htmltext = '<input type=checkbox name="zeroPrice'+count+'" onClick="javascript:setZeroPrice('+( count-1 )+', '+count+')" <%=ConfigManager.isDefaultZeroPriceForSampleSO() ? "CHECKED" : ""%> >';
        }
        else
        {
            htmltext = '<input type=checkbox name="zeroPrice'+count+'" onClick="javascript:setZeroPrice('+( count-1 )+', '+count+')">';
        }
        newCell.innerHTML = htmltext;

        newCell = newRow.insertCell();
        newCell.style.backgroundColor = "#DEE1E2";
        newCell.style.textAlign = "center";
        if ( isSample == 0 )
        {
            htmltext = '<input type=checkbox name="expediteFee'+count+'" disabled="true">';
        }
        else
        {
            htmltext = '<input type=checkbox name="expediteFee'+count+'">';
        }
        newCell.innerHTML = htmltext;
        <%
            if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_CUSTOM_PRICE_FIELD1)) {
         %>
            newCell = newRow.insertCell ();
            newCell.style.backgroundColor = "#DEE1E2";
            htmltext = '<input type="text" name="customPriceField1" size=13 class="valuetxfield" value="0.0" maxlength="9" onkeypress="javascript:restrictCharacters(this,7,<%=ConfigManager.getnoOfDecmalsInAmount()%>)" onkeyup="javascript:restrictAmt(this,7,<%=ConfigManager.getnoOfDecmalsInAmount()%>)" >';
            newCell.innerHTML = htmltext;
         <%
             }
             if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_CUSTOM_TEXT_FIELD1)) {
         %>
                newCell = newRow.insertCell ();
                newCell.style.backgroundColor = "#DEE1E2";
                htmltext = '<textarea name="customTextField1" class="txfield" onkeydown="javascript:setTextAreaMaxLength(this,200)" onkeyup="javascript:setTextAreaMaxLength(this,200)"></textarea>';
                newCell.innerHTML = htmltext;
         <%
             }
         %>
         
        count++;
    }

    function assignShippingInstructions(elementName)
    {
        var shippingInstructions = document.getElementById("shippingInstructions");
        if ( elementName.value == "-1" )
        {
            shippingInstructions.innerHTML = "<bean:message key="label.sales.shippingInstructions" />";
            document.salesOrderForm.shippingInstructions.value = "";
            document.salesOrderForm.shippingInstructions.readOnly = true;
        }
        else if ( elementName.value == "-2")
        {
            shippingInstructions.innerHTML = "New <bean:message key="label.sales.shippingInstructions" />";
            document.salesOrderForm.shippingInstructions.value = "";
            document.salesOrderForm.shippingInstructions.readOnly = false;
            document.salesOrderForm.shippingInstructions.focus();
        }
        else if ( Number( elementName.value ) > 0 )
        {
            enableCustPartNos();
            enablePrices();
            document.salesOrderForm.shippingAddress.disabled = false;
            document.salesOrderForm.billingAddress.disabled = false;

            document.salesOrderForm.salesTaxType.disabled = false;
            document.salesOrderForm.miscAsDouble.disabled = false;
            document.salesOrderForm.frieghtAsDouble.disabled = false;

            document.salesOrderForm.action.value = "loadShippingInstructions";
            document.salesOrderForm.submit();
        }
    }

   function getEndCustomerShippingAddress()
    {
        var endCustomerId      = document.salesOrderForm["odmId"];
        var isEndCustomerShipAddress      = document.salesOrderForm["isEndCustomerShipAddress"];

        var pa                 = document.getElementById("errors1");
        if ( isEndCustomerShipAddress.checked )
        {
            if ( endCustomerId.value <= 0 )
            {
                pa.innerHTML = '<li>Please select <bean:message key="label.sales.endCustomer"/></li>';
                isEndCustomerShipAddress.checked = false;
                return;
            }
        }
        enableFormFields();

        document.salesOrderForm.action.value = "loadEndCustomerDefualtShippingAddress";
        document.salesOrderForm.submit();
    }

   function addShippingMethod(methodname)
   {
        var pa11 = document.getElementById("shippingAccount");
        var pa1  = document.getElementById("newshippingMethod");
        var pa3  = document.getElementById("newshippingAccount");        

		if (methodname.value == -2)
		{
			<%--document.salesOrderForm.newshippingMethod.style.visibility = "visible";
			pa1.innerHTML = "<bean:message key="label.sales.salesOrder.NewShippingMethod"/>:&nbsp;<font color=red>*</font>";

			document.salesOrderForm.newshippingAccount.style.visibility = "visible";
			pa3.innerHTML = "<bean:message key="label.sales.salesOrder.NewShippingAccount"/>:&nbsp;<font color=red>*</font>";--%>
            var form = document.salesOrderForm;
            document.salesOrderForm.shipAccount1.value=-1;
            form.shippingMethod.value = -1;
            form.shippingMethodName.value = " ";
            form.shippingAccount.value = " ";
            var LeftPos=(screen.width)?(screen.width-500)/2:100;
            var TopPos=(screen.height)?(screen.height-450)/2:100;
            newWindow = window.open ('<%=chipTracContext%>/shippingMethodPopupAction.do?action=load&customerId='+form.customerId.value+"&endCustomerId="+form.odmId.value,"editShippingMethod",'channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=540,height=500,resizable=yes,Left= '+LeftPos+',top='+TopPos);
            newWindow.focus();
        }
		else
		{
            document.salesOrderForm.shipAccount1.value = document.salesOrderForm.shippingMethod.value;
            document.salesOrderForm.newshippingMethod.value='';
			document.salesOrderForm.newshippingAccount.value='';

			if (methodname.value == -1)
			{
				document.salesOrderForm.shippingMethodName.value = " ";
				document.salesOrderForm.shippingAccount.value = " ";
			}
			document.salesOrderForm.newshippingMethod.style.visibility = "hidden";
			pa1.innerHTML = "";
			document.salesOrderForm.newshippingAccount.style.visibility = "hidden";
			pa3.innerHTML = "";
			assignShippingAccount(methodname);
		}
	}
    function AddDeliveryTerms ()
	{
		var deliveryTermsLabel = document.getElementById("newDeliveryTerms");
		if(document.salesOrderForm.deliveryTerms.value == -2 )
		{
			 document.salesOrderForm.newDeliveryTerms.style.visibility = "visible";
			 document.salesOrderForm.newDeliveryTerms.value = '';
			 deliveryTermsLabel.innerHTML = "New <bean:message key="label.sales.salesOrder.DeliveryTerms" /> : ";
             document.salesOrderForm.newDeliveryTerms.focus();
		}
		else
		{
			 document.salesOrderForm.newDeliveryTerms.style.visibility = "hidden";
			 deliveryTermsLabel.innerHTML = "";
		}
	}
	function addNewSalesTaxType(statename)
    {
		var p1=document.getElementById("font-1");
		var p2=document.getElementById("font-2");
		var p3=document.getElementById("font-3");
		var p4=document.getElementById("font-4");
		p1.innerHTML = "";
		p2.innerHTML = "";
		p3.innerHTML = "";
		p4.innerHTML = "";
        if(statename.value == -1)
        {
			var htmltext1 = '<font class="NArialL">New State :</font>&nbsp;';
			var htmltext2 = '<input type="text" name="newSalesState" size="18" maxlength="25" class="txfield" onblur ="javascript:taxFocus();" >';
			var htmltext3 = '<font class="NArialL">New Tax :</font>&nbsp;';
			var htmltext4 = '<input type="text" name="newSalesTax" size="18" class="txfield" onkeypress="javascript:restrictCharacters(this,3,<%=ConfigManager.getnoOfDecmalsInAmount()%>)" maxlength="7" onkeyup="javascript:restrictAmt(this,3,<%=ConfigManager.getnoOfDecmalsInAmount()%>)" >'

			p1.insertAdjacentHTML('BeforeEnd',htmltext1);
			p2.insertAdjacentHTML('BeforeEnd',htmltext2);
			p3.insertAdjacentHTML('BeforeEnd',htmltext3);
			p4.insertAdjacentHTML('BeforeEnd',htmltext4);
		}
	}
    function submitPage(action)
    {
        errors = '';
		document.getElementById("errors1").innerHTML = '';
		errors1 = '';
        if(!dateValidation()) {
            errors = errors;
        }
	var qty = document.salesOrderForm["quantity"];
	var price = document.salesOrderForm["unitPriceAsDouble"];
	var partNo = document.salesOrderForm["manufacturingPartNo"];
	var customerpo = document.salesOrderForm["customerPO"];
	var salesorderno = document.salesOrderForm["salesOrderNo"];
	var contactPerson = document.salesOrderForm["contactPerson"];
	var salesPerson = document.salesOrderForm["salesPerson"];
    var endUser = document.salesOrderForm["endUser"];
	var regionalRep = document.salesOrderForm["regionalRep"];
	var shippingAccount = document.salesOrderForm["shippingAccount"];
	var shippingTerms = document.salesOrderForm["shippingTerms"];
	var deliveryTerms = document.salesOrderForm["deliveryTerms"];
	var phoneNumber = document.salesOrderForm["phoneNumber"];
    var email = document.salesOrderForm["email"];
	var faxNumber = document.salesOrderForm["faxNumber"];
	var comments = document.salesOrderForm["comments"];
	var shippingInstructions = document.salesOrderForm["shippingInstructions"];
    var freightInstructions = document.salesOrderForm["freightInstructions"];

	var frieght = document.salesOrderForm["frieghtAsDouble"];
	var misc = document.salesOrderForm["miscAsDouble"];
	var date = document.salesOrderForm["requestDate"];

    document.salesOrderForm.frieghtAsDouble.value = stripCharsInBag(document.salesOrderForm["frieghtAsDouble"].value,"$, ");
    document.salesOrderForm.miscAsDouble.value = stripCharsInBag(document.salesOrderForm["miscAsDouble"].value,"$, ");

    removePrePostSpaces(qty);
    removePrePostSpaces(price);
    if( document.salesOrderForm.salesTaxType.value == -1)
	{
        removePrePostSpaces(document.salesOrderForm["newSalesTax"]);
    }
    removePrePostSpaces(frieght);
    removePrePostSpaces(misc);
        //Quantity validations
        if(document.salesOrderForm["quantity"].length == null)
        {
			if(partNo.value != '')
			{
                if(partNo.value == '---- BOARD -----' || partNo.value == '---- KIT -----' || partNo.value == '---- CHIPS -----')
                {
                    errors = errors +'<br>' + "<li>  Please select the Part Number ";
                }

                if(qty.value != '')
                {
                    if(!isInteger(qty.value))
                    {
                        errors = errors +'<br>' + "<li>  Please enter a valid quantity ";
                        qty.select();
                    }
                    else if(qty.value == 0)
                    {
                        errors = errors +'<br>' + "<li>  Please enter a valid quantity ";
                        qty.select();
                    }
                    else if((qty.value).length > 6)
                    {
                        errors = errors +'<br>' + "<li>  Please enter a valid quantity (should not allow more than 6 digits)";
                        qty.select();
                    }
                }
                else
                {
                    errors = errors +'<br>' + "<li>  Please enter the quantity";
                }

			}
			else
			{
					errors = errors +'<br>' + "<li>  Please select the Part Number ";
			}
         }
         else
         {
            for(var i=0; i< qty.length; i++)
            {
                if(partNo[i].value != '')
                {
					if(partNo[i].value == '---- BOARD -----' || partNo[i].value == '---- KIT -----' || partNo[i].value == '---- CHIPS -----' )
					{
						errors = errors +'<br>' + "<li>  Please select the Part Number for Lineitem"+(i+1);
						break;
					}
                    if (qty[i].value != '')
                    {
			            if(!isInteger(qty[i].value))
                        {
				            errors = errors +'<br>' + "<li>  Please enter a valid quantity ";
				            qty[i].select();
							break;
			            }
                        else if(qty[i].value == 0)
                        {
				            errors = errors + '<br>' +"<li>  Please enter a valid quantity ";
				            qty[i].select();
							break;
			            }
                        else  if((qty[i].value).length > 6)
                        {

				            errors = errors + '<br>' +"<li>  Please enter a valid quantity (should not allow more than 6 digits)";
				            qty[i].select();
							break;
         		        }
                    }
                    else
                    {
			            errors = errors +'<br>' + "<li>  Please enter the quantity";
                        qty[i].select();
						break;
                    }
		        }
                else if( (trim(qty[i].value).length != 1 && trim(qty[i].value) != 0 ) || (trim(date[i].value).length != 0) )
                {
					if(partNo[i].value == '')
                    {
			            errors = errors +'<br>' + "<li>  Please select the Part Number for Lineitem"+(i+1);
			        	break;
					}
                }

            }
         }

          if(document.salesOrderForm["unitPriceAsDouble"].length == null)
          {
            if(price.value != '')
            {
                var j = 0;
                for(var k = 0; k < (price.value).length;k++)
	            {
		            var c = (price.value).charAt(k);
		            if( c == '.' )
		            {
			            j++;
                        if(j > 1 )
                        {
                            errors = errors +'<br>' + "<li>  Please enter a valid price";
	 				        price.select();
							break;
                        }
                    }
               }
			   if(check_char_position4(price.value) || (is_Sp_Characters_frieght(price.value) == false)  )
			   {
					 errors = errors +'<br>' + "<li>  Please enter a valid price";
					 price.select();
			   }
			   if( (price.value).length >= 8 )
				{
					var priceValue = price.value;
					var index = priceValue.indexOf(".");
					if( index == -1 || index > 7 )
					{
						errors = errors +'<br>' + "<li>  Please enter a valid price (price should be in XXXXXX.XX format)";
						price.select();
					}
				}
	        }
            else
            {
	            errors = errors +'<br>' + "<li>  Please enter the price";
	        }
	      }
          else
          {

	        for(var i=0; i< price.length; i++)
	        {
	            if(partNo[i].value != '')
                {

	                if (price[i].value != '')
                    {

                        var j = 0;
                        for(var k = 0; k < (price[i].value).length;k++)
	                    {
		                    var c = (price[i].value).charAt(k);
		                    if( c == '.' )
		                    {
			                    j++;
                                if(j > 1 )
                                {
                                    errors = errors +'<br>' + "<li>  Please enter a valid price";
	 				                price[i].select();
							        break;
                                }
		                    }
	                    }

						if(check_char_position4(price[i].value) || (is_Sp_Characters_frieght(price[i].value) == false) )
                        {
	 				        errors = errors +'<br>' + "<li>  Please enter a valid price";
	 				        price[i].select();
							break;
	 			        }

						if( (price[i].value).length >= 8 )
						{
							var priceValue = price[i].value;
							var index = priceValue.indexOf(".");
							if( index == -1 || index == 8 )
							{
								errors = errors +'<br>' + "<li>  Please enter a valid price (price should be in XXXXXXX.X format)";
								price[i].select();
								break;
							}
						}
	                }
                    else
                    {
	 			        errors = errors +'<br>' + "<li>  Please enter the price";
	                    price[i].select();
						break;
	                }
	 		    }

	            if(partNo[0].value =='')
                {
					errors = "<li>  Please select the Part Number for Lineitem1";
	            }
	        }
	      }

       if( !(is_Sp_Characters_frieght(frieght.value)) || (check_char_position4(frieght.value)) )
	  {

	      errors = errors + '<br>' + "<li>  Freight should be a number ";
	  }

       if( !(is_Sp_Characters_frieght(misc.value)) || (check_char_position4(misc.value)) )
	  {

	      errors = errors + '<br>' + "<li>  Miscellaneous field should be a number ";
	  }
	if( document.salesOrderForm.salesTaxType.value == -1)
	{
	     var newState = document.salesOrderForm.newSalesState.value;
	     var newTax = document.salesOrderForm.newSalesTax.value;

          if( newState.length == 0 || newState == '')
          {
                errors = errors + '<br>' + "<li>  Please enter New State ";
          }
          if( newTax.length == 0 || newTax == '')
          {
                errors = errors + '<br>' + "<li>  Please enter New Tax ";
          }
         if( (newState.length == 0 || newState == '') &&  (newTax.length == 0 || newTax == ''))
          {
                 errors = ''
                 errors = errors + '<br>' + "<li> Please enter values for New State and New Tax";
          }
          if(  newState.length != 0 && newState != '')
          {
              if( !(is_Sp_Characters_State(newState)) || (check_char_position5(newState)) )
              {
                  errors = errors + '<br>' + "<li>  Please enter a valid state ";
              }
         }
        if( newTax.length != 0 && newTax != '')
        {
          var hh = 0;
            if( !(is_Sp_Characters_frieght(newTax)) || (check_char_position4(newTax)) )
            {
               errors = '';
               errors = errors + '<br>' + "<li> New Sales tax should be a number";
            }
            else if(newTax == 0 ||  newTax == '')
            {
                errors = '';
                errors = errors +'<br>' + "<li>  New Tax cannot be less than or equal to zero ";
            }
            for(var d = 0; d < newTax.length;d++)
            {
                var c = (newTax).charAt(d);
                if( c == '.' )
                {
                    hh++;
                    if(hh > 1 )
                    {
                        errors = errors +'<br>' + "<li> New Tax should be valid number and first digit can not be space or zero ";
                        break;
                    }
                }
           } //for
        }

	}

    var statename1 = document.salesOrderForm["salesTaxType"];
    var status = false;

       for( var txble=1; txble < count; txble++ )
       {
	        var txval = "isTaxable"+txble;
            if(document.salesOrderForm[txval] != null)
            {
	            if( document.salesOrderForm[txval].checked == true )
                {
                    <%-- status is set to true only if the part no is selected for the line item whose 'isTaxable' is checked --%>
                    if(document.salesOrderForm["quantity"].length == null)
                    {
                        if(partNo.value != '')
                        {
                            if(!(partNo.value == '---- BOARD -----' || partNo.value == '---- KIT -----' || partNo.value == '---- CHIPS -----'))
                            {
                                status = true;
                            }
                        }
                    }
                    else
                    {
                        if(partNo[txble-1].value != '')
                        {
                            if(!(partNo[txble-1].value == '---- BOARD -----' || partNo[txble-1].value == '---- KIT -----' || partNo[txble-1].value == '---- CHIPS -----'))
                            {
                                status = true;
                            }
                        }
                    }
	                if( (statename1.value == 0) && (status == true) )
	                {
                        errors = errors+ '<br>' +"<li>  Please either select Tax from Sales Tax State or uncheck Taxable field";
                        break;
	                }
                }
            }
       }//for

        if( (statename1.value != 0) && (status == false))
           {
     	     errors = errors+ '<br>' +"<li>  Please either check atleast one Taxable field or Select NonTaxable option";
            }

        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
		       if(  (!(is_Sp_Characters(salesorderno.value))) || (check_char_position(salesorderno.value))  )
			{
			    	 errors = errors + '<br>' + "<li>  SalesOrderNo should be a numerical and not start with  special char";
			}
              var errors1 = "";

	          if( (!(is_Sp_Characters(customerpo.value)) ) || (check_char_position(customerpo.value))  )
			  {
			     errors1 = errors1 + '<br>' + "<li>  Customer PO No: will accept alphanumeric and special characters -, _ only";
			  }

            if( (text_area(comments.value)) == true)
            {
                errors = errors + '<br>' + "<li>  Comments should not more than 300 Characters ...";
            }

            if( salesPerson.value < 0 )
            {
                document.salesOrderForm["salesPerson"].value = "";
            }

            if( (text_area(shippingInstructions.value)) == true)
            {
                errors = errors + '<br>' + "<li>  ShippingInstructions should not exceed 300 characters";
            }

            if( (text_area(freightInstructions.value)) == true)
            {
                errors = errors + '<br>' + "<li>  FreightInstructions should not exceed 300 characters";
            }
				var shipmethod = document.salesOrderForm.shippingMethod.value;
				var shipaccount = document.salesOrderForm.shippingAccount.value;

            if( document.salesOrderForm.poDate.value != '' && !validateBookingDate( document.salesOrderForm.poDate.value ) )
            {
                errors1 = '<br>'+"<li> PO Date should be in 'mm/dd/yyyy' format ";
				document.salesOrderForm.poDate.select();
                document.salesOrderForm.poDate.focus();
            }

            // blank customer po number is not allowed in sales order.
            if( isSample == 1 )
            {
                if(document.salesOrderForm.customerPO.value == '')
                {
                    document.salesOrderForm.customerPO.focus();
                    errors1 = errors1 + '<br>' + "<li>  Please enter Customer PO No";
                    location="#e1";
                }
            }
            if( email.value != '' )
            {
               if(!isValidEMailId (email))
                {
                errors1=errors1+ '<br>'+'<li> Please enter a valid email address';
                email.select();
                email.focus();
                }
            }
            if ( document.salesOrderForm.isConsignee.value == 'true' && document.salesOrderForm.isConsignmentSales.value == "" )
            {
                errors1 = errors1+ "<li> Please specify whether this sales order is Invoice to Customer or Not";
				document.salesOrderForm.isConsignmentSales.focus();                
            }
            if( document.salesOrderForm.salesOrderDate.value.trim() == "" )
            {
                errors1 = errors1+ '<br>'+"<li> Booking Date cannot be blank";
				document.salesOrderForm.salesOrderDate.select();
                document.salesOrderForm.salesOrderDate.focus();
            }
			else if(!validateBookingDate(document.salesOrderForm.salesOrderDate.value))
            {
                errors1 = errors1 + '<br>'+"<li> Booking Date should be in 'mm/dd/yyyy' format ";
				document.salesOrderForm.salesOrderDate.select();
                document.salesOrderForm.salesOrderDate.focus();
            }
            <%
                if ( ConfigManager.isEndUserMandatory() )
                {
            %>
                    if ( document.salesOrderForm.endCustomerId.value == '-1' || document.salesOrderForm.endCustomerId.value == '' )
                    {
                        errors1 = errors1+ '<li> Please select <bean:message key="label.sales.endUser"/>';
                        document.salesOrderForm.endCustomerId.focus();
                    }
                    else if ( document.salesOrderForm.endCustomerId.value == '-2' && document.salesOrderForm.newEndUserName.value.trim() == '' )
                    {
                        errors1 = errors1+ '<li> Please enter new <bean:message key="label.sales.endUser"/>';
                        document.salesOrderForm.newEndUserName.focus();
                    }
            <%
                }
            %>
            <%
                if ( ConfigManager.isEndCustomerMandatory() )
                {
            %>
                    if ( document.salesOrderForm.odmId.value == '-1' || document.salesOrderForm.odmId.value == '' )
                    {
                        errors1 = errors1+ '<li> Please select <bean:message key="label.sales.endCustomer"/>';
                        document.salesOrderForm.odmId.focus();
                    }
                    else if ( document.salesOrderForm.odmId.value == '-2' && document.salesOrderForm.newEndCustomerName.value.trim() == '' )
                    {
                        errors1 = errors1+ '<li> Please enter new <bean:message key="label.sales.endCustomer"/>';
                        document.salesOrderForm.newEndCustomerName.focus();
                    }
            <%
                }
            %>
            if( document.salesOrderForm["shippingAddress"].value == '' )
            {
                errors1=errors1+ '<br>'+'<li> Please enter shipping Address';
            }
		/** to do validations for salaes order No
		  * and also commented as we made sales order No as static value (bean:write instead of text field)
		  * (If we want to make it text field then remove simply these comments so that we get validations for * * sales order no)
		  */

			var salesOrderNo = document.salesOrderForm.salesOrderNo.value ;
			if( salesOrderNo == '')
			{
				document.salesOrderForm.salesOrderNo.focus();
				errors1 = errors1 + '<br>' + "<li>  Please enter Sales Order No";
				location="#e1";
			}
			else
			 if( salesOrderNo != '')
			 {
                if( chkSalesOrderNoBegin(salesOrderNo) )
				 {
					document.salesOrderForm.salesOrderNo.focus();
					errors1 = errors1 + '<br>' + "<li>  Sales Order No should not start with special characters ";
					location="#e1";
                 }
				 else
                 if( ! chkSalesOrderNo(salesOrderNo) )
                 {
					 document.salesOrderForm.salesOrderNo.focus();
					 errors1 = errors1 + '<br>' + "<li>  Please enter Valid Sales Order No ";
					 location="#e1";
                 }
             }

        var method1     = document.salesOrderForm.shippingMethod.value;
		var account1    = document.salesOrderForm.shippingAccount.value;
		var newmethod1  = document.salesOrderForm.newshippingMethod.value;
		var newaccount1 = document.salesOrderForm.newshippingAccount.value;
        if( method1 == -2)
        {
            if( trim(newmethod1) == '')
            {
                errors1 = errors1+'<br>'+'<li> Enter <bean:message key="label.sales.salesOrder.NewShippingMethod"/> ';
                document.salesOrderForm.newshippingMethod.select();
            }
            if( trim(newaccount1) == '')
            {
                errors1 = errors1+'<br>'+'<li> Enter <bean:message key="label.sales.salesOrder.NewShippingAccount"/> ';
                document.salesOrderForm.newshippingAccount.focus();
            }
            if(newmethod1.indexOf('\'')>=0 || newmethod1.indexOf('"')>=0 || newmethod1.indexOf('#')>=0)
            {
                errors1 = errors1+'<br>'+'<li> Enter Valid <bean:message key="label.sales.salesOrder.NewShippingMethod" /> ( \' " # are not allowed ) ';
                document.salesOrderForm.newshippingMethod.select();
                document.salesOrderForm.newshippingMethod.focus();
            }
            if(newaccount1.indexOf('\'')>=0 || newaccount1.indexOf('"')>=0  || newaccount1.indexOf('#')>=0)
            {
                errors1 = errors1+'<br>'+'<li> Enter Valid <bean:message key="label.sales.salesOrder.NewShippingAccount" /> ( \' " # are not allowed ) ';
                document.salesOrderForm.newshippingAccount.select();
                document.salesOrderForm.newshippingAccount.focus();
            }

            <%
            if( Constants.SALES_INTEGRATION_TYPE_GREAT_PLAINS.equals( ConfigManager.getSalesIntegrationType() ) )
            {
            %>
                var tempShippingMethod =  newmethod1.trim();
                for(var i = 0; i < shppingLables.length - 1; i++)
                {
                    if(  shppingLables[i].substring( 0, shppingLables[i].indexOf("#") ).toUpperCase().trim() == tempShippingMethod.toUpperCase() )
                    {
                        errors1 = errors1+'<li>' + newmethod1 + ' <bean:message key="label.sales.salesOrder.ShippingMethod" /> already Exists, Please enter another <bean:message key="label.sales.salesOrder.ShippingMethod" />';
                        document.salesOrderForm.newshippingMethod.select();
                        document.salesOrderForm.newshippingMethod.focus();
                    }
                }
            <%
            }
            else
            {
            %>
                var tempShippingMethod =  newmethod1.trim()+'   #   '+newaccount1.trim();
                for(var i = 0; i < shppingLables.length - 1; i++)
                {
                    if(  shppingLables[i].toUpperCase() == tempShippingMethod.toUpperCase() )
                    {
                        errors1 = errors1+'<li>' + newmethod1 + ' <bean:message key="label.sales.salesOrder.ShippingMethod" /> already Exists, Please enter another <bean:message key="label.sales.salesOrder.ShippingMethod" />';
                        document.salesOrderForm.newshippingMethod.select();
                        document.salesOrderForm.newshippingMethod.focus();
                    }
                }
            <%
            }
            %>
        }

		var shipTerms = document.salesOrderForm.shippingTerms.value;
		var newshipTerms = document.salesOrderForm.newShippingTerms.value;
        var deliveryTerms = document.salesOrderForm.deliveryTerms.value;
	    var newDeliveryTerms = document.salesOrderForm.newDeliveryTerms.value;
		if( shipTerms == -2 )
		{
			if( newshipTerms == '' || newshipTerms.trim().length == 0 )
			{
				errors1 = '<br>'+'<li> Enter New Pay Terms ';
			}
            else if( newshipTerms.indexOf('\'') >=0 || newshipTerms.indexOf('"') >= 0 )
            {
                errors1 = '<br>'+'<li> Enter Valid Pay Terms ';
                document.salesOrderForm.newShippingTerms.select();
                document.salesOrderForm.newShippingTerms.focus();
            }

		}
        if( deliveryTerms == -2 )
        {
            if ( newDeliveryTerms == '' || newDeliveryTerms.trim().length == 0 )
            {
                errors1 = errors1+'<br>'+'<li> Enter New <bean:message key="label.sales.salesOrder.DeliveryTerms" />'
            }
            else if( newDeliveryTerms.indexOf('\'') >= 0 || newDeliveryTerms.indexOf('"') >= 0)
            {
                errors1 = errors1+'<br>'+'<li> Enter Valid <bean:message key="label.sales.salesOrder.DeliveryTerms" />';
                document.salesOrderForm.newDeliveryTerms.select();
                document.salesOrderForm.newDeliveryTerms.focus();
            }
        }
		if(errors1 != '')
        {
            var pa=document.getElementById("errors1");
            pa.innerHTML = errors1;
			return;
        }
		if(errors != '')
        {
            var pa=document.getElementById("errors");
            pa.innerHTML = errors;

	        return;
        }

        document.salesOrderForm.shippingAddress.disabled = false;
        document.salesOrderForm.billingAddress.disabled = false;
        document.salesOrderForm.phoneNumber.disabled = false;
        document.salesOrderForm.faxNumber.disabled = false;
        document.salesOrderForm.email.disabled = false;
		document.salesOrderForm.contactPerson.disabled = false;

        document.salesOrderForm.salesTaxType.disabled = false;
        document.salesOrderForm.miscAsDouble.disabled = false;
        document.salesOrderForm.frieghtAsDouble.disabled = false;

        if(document.salesOrderForm["quantity"].length==null)
        {
             var element = eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.jsLineItemNo.value) );
            if(element.checked == true &&  price.value > 0 )
            {
                pa.innerHTML = "<li>Price field can not take a value greater than zero when \" zero price \" option is selected";
                price.focus();
                return;
            }
        }
        else
        {
            var zeroPriceCount=document.salesOrderForm["quantity"].length;

            for(i=0;i< zeroPriceCount;i++)
            {
                if(qty[i].value > 0 )
                {
                    var element = eval( "document.salesOrderForm.zeroPrice" + (document.salesOrderForm.jsLineItemNo[i].value) );
                    if(element != null)
                    {
                        if(element.checked == true &&  price[i].value > 0 )
                        {
                            pa.innerHTML = "<li>Price field can not take a value greater than zero when \" zero price \" option is selected";
                            price[i].focus();
                            return;
                        }
                    }
                }
            }
        }
        var description = document.salesOrderForm["lineItemDescription"];
        var length = document.salesOrderForm["lineItemDescription"].length;
        if(length == null)
        {
            if(description.value.length > 200)
            {
                   pa.innerHTML = "<li>Description Should be Maximum of 200 Characters. ";
                   description.focus();
                   description.select();
                   return;
            }
        }
        else
        {
            for(var i=0;i< length;i++)
            {
                if(description[i].value.length > 200)
                 {
                     pa.innerHTML = "<li>Description Should be Maximum of 200 Characters. ";
                     description[i].focus();
                     description[i].select();
                     return;
                 }

            }
        }
        enableCustPartNos();

        enablePrices();

        document.salesOrderForm.submit();

        if(action == 'UPDATE')
            document.salesOrderForm.action.value = "UpdateSalesOrder";
        else if(action == 'SUBMIT')
            document.salesOrderForm.action.value = "SubmitSalesOrder";
            document.salesOrderForm.shippingAccount.disabled=false;
            enableCustPartNos();

            enablePrices();

            document.salesOrderForm.submit();
    }
      var keys = new Array();
      var comments = new Array();

    <%
         //java.util.HashMap mapComments = null;

         try{
                mfgList = salesOrderFromMap.getMfgParts();
                if( mfgList == null)  mfgList =  new java.util.ArrayList();
                mfgListsize = mfgList.size();
                int commentCount = 0;
                strBuffer = new StringBuffer();
                for( int j = 0; j < mfgListsize; j++)
                {
                    customerPartNo = (CustomerPartNumber)mfgList.get(j);
                    strBuffer.append("keys[").append(commentCount).append("]='").append(customerPartNo.getManufacturingPartNo()).append("';\n");
                    out.print( "comments["+commentCount+"]='");
                    if ( customerPartNo.getComments() != null)
                    {
                        out.print(StringUtils.escapeSpecialString(customerPartNo.getComments()));
                     }   
                    out.println("';");
                    commentCount++;
                }
                 /*mapComments = salesOrderFromMap.getMfgPartsWithComments();
                 java.util.Iterator mapKeyIterator = mapComments.keySet().iterator();
                 int count =0;
                 strBuffer = new StringBuffer();
                 while( mapKeyIterator.hasNext() )
                 {
                     Object key = mapKeyIterator.next();
                     strBuffer.append("keys[").append(count).append("]='").append(key).append("';\n");
                     out.print( "comments["+count+"]='");
                     if(mapComments.get(key)!=null)
                     {
                        out.print(StringUtils.escapeSpecialString((String)mapComments.get(key)) );
                     }
                     out.println("';");
                     count++;
                 } */
                out.println(strBuffer.toString());
            }
            catch(Exception ex)
            {   //ex.printStackTrace();
            	System.out.println(ex);
            }
        %>
        <%=ChangeOrderAction.getMapScript( salesOrderFromMap.getMfgPartsWithCustomerPartNos(), "customernos", false)%>
        var baseOrderQty = new Array();
        <%
          if ( ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_BASE_ORDER_QTY) )
          {
            java.util.HashMap mapBaseOrderQty = null;
            try{
               mapBaseOrderQty = salesOrderFromMap.getMfgPartsWithBaseOrderQty();
               java.util.Iterator mapKeyIterator = mapBaseOrderQty.keySet().iterator();
               int noCnt = 0;
               strBuffer1 = new StringBuffer();
               while( mapKeyIterator.hasNext() )
               {
                     Object key = mapKeyIterator.next();
                     out.print( "baseOrderQty["+noCnt+"]='");
                     if(mapBaseOrderQty.get(key)!=null)
                     {
                        out.print(((String)mapBaseOrderQty.get(key)));
                     }
                     out.println("';");
                     noCnt++;
               }
           }
          catch(Exception ex)
            {
            	System.out.println(ex);
            }
          }
        %>
        var labelnos = new Array();
        <%
           /*java.util.HashMap mapLabelNo = null;
           try{
               mapLabelNo = salesOrderFromMap.getMfgPartsWithLabelNumbers();
               java.util.Iterator mapKeyIterator = mapLabelNo.keySet().iterator();
               int noCnt = 0;
               strBuffer1 = new StringBuffer();
               while( mapKeyIterator.hasNext() )
               {
                     Object key = mapKeyIterator.next();
                     out.print( "labelnos["+noCnt+"]='");
                     if(mapLabelNo.get(key)!=null)
                     {
                        out.print(((String)mapLabelNo.get(key)));
                     }
                     out.println("';");
                     noCnt++;
               }
           }
          catch(Exception ex)
            {
            	System.out.println(ex);
            } */
        %>


function showErrorReportPage()
{
    newWindow = window.open ('<%=chipTracContext%>/reportProblem.do','reportProblem','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=750,height=400,resizable=no');
    newWindow.focus();
}

function selectCustomerSalesPersonRelation()
{
    var customerId = document.salesOrderForm.customerId.value ;
    var customerName = document.salesOrderForm.customerName.value;
    var odmId = document.salesOrderForm.odmId.value ;
    var LeftPos=(screen.width)?(screen.width-500)/2:100;
    var TopPos=(screen.height)?(screen.height-450)/2:100;
    newWindow = window.open ('<%=chipTracContext%>/customerSalesPersonRelationship.do?action=searchSalesPersons&customerId='+customerId+'&odmId='+odmId,'customerSalespersons','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=yes,width=540,height=500,resizable=yes,Left= '+LeftPos+',top='+TopPos);
    if(!newWindow.opener) {newWindow.opener = window}
    newWindow.focus();
}

function changeSONumber()
{
    var form = document.salesOrderForm;
    var isConsignmentSales = form.isConsignmentSales;
    var salesOrderNoCtrl = form.salesOrderNo;
    var salesOrderNo = salesOrderNoCtrl.value.trim();
    if ( isConsignmentSales.value == "0" )
    {
        salesOrderNo = "<%=Constants.CONSIGNMENT_SALESORDER_NO_PREFIX%>" + "-" + salesOrderNo;
    }
    else
    {
        var idx = salesOrderNo.indexOf( '-' );
        salesOrderNo = salesOrderNo.substr(idx+1);
    }
    salesOrderNoCtrl.value = salesOrderNo;
}
function partNoGenerator(lineItemIdx)
{
    var form = document.salesOrderForm;
    form.partLineItemNo.value = lineItemIdx;
    var pa = document.getElementById("errors");
    pa.innerHTML = "";
    newWindow = window.open('<%=chipTracContext%>/jsp/partnumber-generator/PartNumberGenerators.html','PartNumberGeneratorsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=650,height=525,resizable=yes');
    newWindow.focus();
}

</SCRIPT>
<!-- Top Header Start-->
    <%
        String userTypeChiptrac = Constants.USER_TYPE_CHIPTRAC + "";
    %>
    <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/includes/header.jsp" %>
    </logic:equal>
    <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/includes/extHeader.jsp" %>
    </logic:notEqual>

<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->
<% String heading = ""; %>
<% if((request.getParameter("isSample") != null) && (request.getParameter("isSample").equals("0"))) {
        heading = "Sample Order";
        isSample = 0;
%>
	    <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
            <%@ include file="/jsp/sales/sample_order_menu.jsp" %>
        </logic:equal>
        <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
            <%@ include file="/jsp/sales/ext_sample_order_menu.jsp" %>
        </logic:notEqual>
<% } else {
    heading = "Sales Order";
    isSample = 1;
%>
        <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
            <%@ include file="/jsp/sales/sales_order_menu.jsp" %>
        </logic:equal>
        <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
            <%@ include file="/jsp/sales/ext_sales_order_menu.jsp" %>
        </logic:notEqual>
<% } %>


</TD>
<!-- end of the side navigations -->
<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>
<html:html>


<!-- from here your body starts -->
<table width="75%"><tr><td ><center><span class="NArialW"><%=heading%> Entry</span></center></td></table>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10>


    <table border="0" width="95%" align=right>
    <% if( isSample == 1 && !user1.isActionAllowed( Functionality.SALES_NEW_SALES_ORDER, User.USER_ACTION_MODIFY ) ) { %>
        <tr><td colspan=7 align='left'><font class='NArialS'><font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b></font></font></td></tr>
    <% }else if( isSample == 0 && !user1.isActionAllowed( Functionality.SAMPLE_NEW_SAMPLE_ORDER, User.USER_ACTION_MODIFY ) ) { %>
        <tr><td colspan=7 align='left'><font class='NArialS'><font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b></font></font></td></tr>
    <%  } %>
<html:form name="salesOrderForm" action="/salesOrder" method="post" type="com.scalar.chiptrack.sales.forms.SalesOrderForm">
<% SalesOrderForm salesOrderForm = (SalesOrderForm) request.getAttribute("salesOrderForm"); %>
    <tr><td><a name="#e1"></a></td></tr>
	 <tr><td colspan=6 class="NArialL"><chiptrack:errors styleClass="NArialL"  /></td></tr>

    <tr><td  colspan="6" align="left" class='NArialL'><FONT id="errors1" styleClass="NArialL" color='FF0000'></FONT></TD></TR>
    <tr>
	   <td width="13%"><font class="NArialL">Sales Order No:&nbsp;<font color=red>*</font></font></td>
       <td width="18%">
		<html:text name="salesOrderForm" property="salesOrderNo" styleClass="txfield" size="23" maxlength="50" />
		</td>
       <td width="15%"><font class="NArialL">Customer Name :</font></td>
       <td width="20%" class="bodytext"><b><bean:write name="salesOrderForm" property="customerName" /></b></td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
    </tr>

    <tr>
       <td width="13%"><font class="NArialL">Customer PO No :&nbsp;
        <logic:notEqual parameter="isSample" value="0">
            <font color=red>*</font>
        </logic:notEqual>
       </font></td>
       <td width="18%"><html:text name="salesOrderForm" property="customerPO" styleClass="txfield" size="23" maxlength="50" onkeyup=""/></td>
       <td width="15%"><font class="NArialL">Contact Person :</font></td>
       <td width="20%">

       <html:select name="salesOrderForm" property="contactPerson"  styleClass="txfield" onchange="javascript:selectContactPerson('CustomerContactPerson',0);">
	   <html:option value="">--- Select ---</html:option>
	   <html:options name="contactPersons" />
	   </html:select>
	   </td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
    </tr>
    <tr>
       <td width="13%"><font class="NArialL">Quotation No :&nbsp;
       </font></td>
       <td width="18%"><html:text name="salesOrderForm" property="quotationNo" styleClass="txfield" size="23" maxlength="50" onkeyup=""/></td>
       <td width="15%"><font class="NArialL">&nbsp;</font></td>
       <td width="20%">
       </td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
    </tr>
    <tr>
       <td width="13%" nowrap ><font class="NArialL"><bean:message key="label.sales.salesOrder.PoRevisionNumber"/> :</font></td>
       <td width="18%"><html:text name="salesOrderForm" property="poRev" size="23" styleClass="txfield" /></td>
       <td width="15%"><font class="NArialL"><bean:message key="label.sales.salesOrder.PoDate"/> :</td>
       <td width="20%"><html:text name="salesOrderForm" property="poDate" size="23" styleClass="txfield" />
       <a href="javascript:openCalendar(document.salesOrderForm.poDate)"><img onMouseOver="window.status='Click here to select date';return true" border="0" align='center' src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
       </td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
    </tr>

     <tr>
       <td width="13%" class="NArialL">Phone :</td>
       <td width="18%"><html:text name="salesOrderForm" property="phoneNumber" size="23" styleClass="txfield" onkeypress='validatePhoneNumber(this)'/></td>
       <td width="15%" class="NArialL">Cell No :</td>
       <td width="20%"><html:text name="salesOrderForm" property="cellNumber" size="23" styleClass="txfield" onkeypress='validatePhoneNumber(this)'/></td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
     </tr>
     <tr>
       <td width="13%"><font class="NArialL">Fax :</font></td>
       <td width="18%"><html:text name="salesOrderForm" property="faxNumber" size="23" styleClass="txfield" disabled="false" onkeypress='validatePhoneNumber(this)'/></td>
       <td width="15%"><font class="NArialL">Email :</font></td>
       <td width="20%"><html:text name="salesOrderForm" property="email" size="23" styleClass="txfield"/></td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
     </tr>
	 <tr>
       <td width="13%"><font class="NArialL">Sales Person :</font></td>
       <td width="18%">
        <html:select name="salesOrderForm" property="salesPerson" styleClass="txfield" >
            <html:option value="" >----- Select -----</html:option>
    	    <html:options collection="salesPersons" property="value" labelProperty="label"/>
        </html:select>
       <input type="hidden" name="salesPersonName" value="<%= salesOrderForm.getSalesPerson()%>" />
       </td>
       <td width="15%"><font class="NArialL"><bean:message key="label.sales.salesRep.Name"/> :</font></td>
       <td width="20%">
        <html:select name="salesOrderForm" property="salesRep" styleClass="txfield" >
            <html:option value="" >----- Select -----</html:option>
    	    <html:options collection="salesReps" property="value" labelProperty="label"/>
        </html:select>
        <input type="hidden" name="salesRep" value="<%= salesOrderForm.getSalesRep()%>" />
       </td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
     </tr>
     <tr>
        <td colspan="3"><font class="NArialL">Please <a styleClass="leftsection" href="javascript:selectCustomerSalesPersonRelation()" onmouseover="window.status='Click to select Customer/Sales Person Relationship';return true" onmouseout="window.status='';return true">
        Click here</a>&nbsp;to Add Customer/Sales Person Relationships
        </font></td>
        <td width="8%">&nbsp;</td>
        <td width="20%">&nbsp;</td>
     </tr>
     <tr>
       <td width="13%"><font class="NArialL"><bean:message key="label.sales.salesOrder.ShippingMethod" /> :</font></td>

	       <td width="18%">
	   	   <select name="shippingMethod" class="txfield" onchange="javascript:addShippingMethod(this);">
		   <option value="-1" >----- Select -----</option>
		   <% java.util.ArrayList shippingMethods = null;

			   boolean flagValue = false;
		     try
			 {
			   if(request != null)
			   {
					selectedMethod = (String)request.getAttribute("Method");
					selectedAccount = (String)request.getAttribute("Account");
					shippingMethods = salesOrderFromMap.getShippingMethods ();
					org.apache.struts.util.LabelValueBean shippingMethod;
				   for(int j=0; j<shippingMethods.size(); j++)
				   {
					   shippingMethod = (org.apache.struts.util.LabelValueBean)shippingMethods.get(j);
					   String label = shippingMethod.getLabel();
					   String value = shippingMethod.getValue();

					   if( selectedMethod != null)
					   {
					        if((selectedMethod.trim()).equalsIgnoreCase(label.trim())  )
					        {   %>
						        <option value="<%=selectedMethod%>" selected><%=selectedMethod%></option>
                          <%} else if ( "'".equalsIgnoreCase( value ) ) { %>
                                <option value="-1" ><%=label%></option>
						  <%} else 	{ %>
						        <option value="<%=label%>" ><%=label%></option>
					      <%}
				   	   } else { %>
						        <option value="<%=label%>" ><%=label%></option>
					 <%}
				  }//for
			   }//if
			 } catch(NullPointerException e) {e.printStackTrace();}
			%>
            <option value="-2" >----- Edit -----</option>
       </select>
	           </td>

        <input type="hidden" name="shippingAccount" value="<%= salesOrderForm.getShippingAccount() != null ? salesOrderForm.getShippingAccount() : "" %>" />
        <html:hidden property="isConsignee" name="salesOrderForm"/> 
        <logic:equal value="true" name="salesOrderForm" property="isConsignee">
           <td width="15%" class="NArialL">Invoice to Customer :&nbsp;<font color=red>*</font></td>
           <td width="20%">
                <html:select property="isConsignmentSales" name="salesOrderForm" styleClass="txfield" onchange="changeSONumber()" >
                    <html:option value="">--- Select ---</html:option>
                    <html:option value="1">Yes</html:option>
                    <html:option value="0">No</html:option>
                </html:select>
           </td>
        </logic:equal>
        <td width="22%">&nbsp;</td>
        <td width="11%">&nbsp;</td>
     </tr>


    <tr>
       <td width="13%"><font class="NArialL" id="newshippingMethod"><bean:message key="label.sales.salesOrder.NewShippingMethod"/>:</font></td>
       <td width="18%"><html:text name="salesOrderForm" property="newshippingMethod" size="23" styleClass="txfield" maxlength="50" /></td>
       <td width="15%"><font class="NArialL" id="newshippingAccount"><bean:message key="label.sales.salesOrder.NewShippingAccount"/>:</font></td>
       <td width='20%'><html:text name="salesOrderForm" property="newshippingAccount" size="23" maxlength="50" styleClass="txfield" /></td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
     </tr>
    <tr>
       <td width="13%"><font class="NArialL">Pay Terms :</font></td>
       <td width="18%"  >
            <html:select name="salesOrderForm" property="shippingTerms" styleClass="txfield" onchange="javascript:AddShippingTerms()">
                <option value="" >----- Select -----</option>
           <html:options name="allShippingTerms" />
		   <html:option value="-2" >-- Add New Pay Terms --</html:option>
           </html:select>
        </td>
       <td width="15%"><font class="NArialL"><bean:message key="label.sales.salesOrder.DeliveryTerms" /> :</font></td>
       <td width="20%">
       <html:select name="salesOrderForm" property="deliveryTerms" styleClass="txfield" onchange="javascript:AddDeliveryTerms()">
           <option value="" >----- Select -----</option>
           <html:options name="allDeliveryTerms"/>
           <html:option value="-2">-- Add New <bean:message key="label.sales.salesOrder.DeliveryTerms" /> --</html:option>
       </html:select>
       </td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
     </tr>
	 <tr>
       <td width="13%"><font class="NArialL" id="newShippingTerms">New Pay Terms:</font></td>
	   <td width="18%"><html:text name="salesOrderForm" property="newShippingTerms" size="23" maxlength="<%=ConfigManager.getProperty(ConfigManager.PAYMENT_TERMS_MAX_LENGTH)%>" styleClass="txfield" /></td>
       <td width="15%"><font class="NArialL" id="newDeliveryTerms">New <bean:message key="label.sales.salesOrder.DeliveryTerms" />:</font></td>
       <td width="20%"><html:text name="salesOrderForm" property="newDeliveryTerms" size="23" maxlength="50" styleClass="txfield" /></td>
       <td width='22%'>&nbsp;</td>
       <td width='11%'>&nbsp;</td>
	 </tr>
    <tr>
       <td width="13%"><font class="NArialL">Regional Rep :</font></td>
       <td width="18%"> <html:text name="salesOrderForm" property="regionalRep" size="23" styleClass="txfield" />
        </td>
       <td width="15%"><font class="NArialL">Booking Date :&nbsp;<font color=red>*</font></font></td>
       <td width="20%"><html:text name="salesOrderForm" property="salesOrderDate" size="23" styleClass="txfield"/>
        <a href="javascript:openCalendar(document.salesOrderForm.salesOrderDate)"><img onMouseOver="window.status='Click here to select date';return true" border="0" align='center' src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
        </td>
       <td width='22%'>&nbsp;</td>
       <td width='11%'>&nbsp;</td>
     </tr>
     <tr>
       <td width="13%"><font class="NArialL"><bean:message key="label.sales.userField1" /> :</font></td>
       <td width="18%"><html:text name="salesOrderForm" property="userField1" size="23" styleClass="txfield" /></td>
       <td width="15%"><font class="NArialL"><bean:message key="label.sales.userField2" /> :</td>
       <td width="20%"><html:text name="salesOrderForm" property="userField2" size="23" styleClass="txfield" /></td>
       <td width='22%'>&nbsp;</td>
       <td width='11%'>&nbsp;</td>
     </tr>
     <tr>
       <td width="13%"><font class="NArialL"><bean:message key="label.sales.endUser"/> :</font></td>
       <td width="18%">
        <html:select name="salesOrderForm" property="endCustomerId" styleClass="txfield" onchange="showHideNewEndUserField()">
            <html:option value="" >----- Select -----</html:option>
    	    <html:options collection="endCustomerList" property="value" labelProperty="label"/>
            <html:option value="-2" >-----Add New-----</html:option>
        </html:select>
        <html:hidden name="salesOrderForm" property="endCustomer" />
        <input type="hidden" name="endUser" value="" />
       </td>
       <td width="15%"><font class="NArialL"><bean:message key="label.sales.shipToCustomer"/></font></td>
       <td width="20%">
          <html:select name="salesOrderForm" property="odmId" styleClass="txfield" onchange="javascript:getCustomerShippingAddress();"> <%--onchange="javascript:selectODM(this);"--%>
            <html:option value="-1" >----- Select -----</html:option>
            <html:options collection="odmList" property="value" labelProperty="label"/>
            <html:option value="-2" >-----Add New-----</html:option>
          </html:select>
        <html:hidden name="salesOrderForm" property="odm" />
        </td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>

     </tr>
     <tr>
       <td class="NArialL"><span id="endUserLabelSpan" style="display:none">Add New <bean:message key="label.sales.endUser"/> :</span></td>
       <td ><span id="endUserTxfieldSpan" style="display:none"><html:text name="salesOrderForm" property="newEndUserName" styleClass="txfield"/></span></td>
       <td class="NArialL"><span id="endCustomerLabelSpan" style="display:none">Add New <bean:message key="label.sales.shipToCustomer"/></span></td>
       <td ><span id="endCustomerTxfieldSpan" style="display:none"><html:text name="salesOrderForm" property="newEndCustomerName" styleClass="txfield"/></span></td>

       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
    </tr>
    <tr>
       <td width="13%">&nbsp;</td>
       <td width="18%">&nbsp;</td>
       <td width="15%"><font class="NArialL"><bean:message key="label.sales.shipToCustomer"/> </font></td>
       <td width="20%">

       <html:checkbox name="salesOrderForm" property="isEndCustomerShipAddress" value="true" styleClass="txfield" onclick="javascript:getEndCustomerShippingAddress(this);" />

       </td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
    </tr>
    <tr>
       <% if(ConfigManager.isMultipleBillingAddressesAllowed()) { %>
       <td width="13%"><font class="NArialL">Billing Addresses :</font></td>
       <td width="18%">
            <html:select name="salesOrderForm" property="billingAddressId" styleClass="txfield" onchange="javascript:assignBillingAddress(this);">
                <html:options collection="billingAddresses" property="value" labelProperty="label"/>
            </html:select>
       </td>
       <% } else { %>
            <td width="13%"><font class="NArialL"><html:hidden property="billingAddressId" name="salesOrderForm"/></font></td>
           <td width="18%">&nbsp;</td>
       <% } %>
       <td width="15%"><font class="NArialL">Shipping Addresses :</font></td>
       <td width="20%">
          <html:select name="salesOrderForm" property="shippingAddressId" styleClass="txfield" onchange="javascript:assignShippingAddress(this);">

            <html:options collection="shippingAddresses" property="value" labelProperty="label"/>
          </html:select>
        </td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
     </tr>
     <tr>
       <td width="13%"><font class="NArialL">Contact Person :</font></td>
       <td width="18%"><html:select  name="salesOrderForm" property="billingContactPerson"  styleClass="txfield" onchange="javascript:selectContactPerson('BillingContactPerson',0,0);" >
	   <html:option value="">--- Select ---</html:option>
	   <html:options name="billingAddressContactPersons" />
	   </html:select></td>
       <td width="15%"><font class="NArialL">Contact Person :</font></td>
       <td width="20%">
	   <html:select  name="salesOrderForm" property="shippingContactPerson"  styleClass="txfield" onchange="javascript:selectContactPerson('ShippingContactPerson',0,0);">
	   <html:option value="">--- Select ---</html:option>
	   <html:options name="shippingAddressContactPersons" />
	   </html:select>
	   </td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
    </tr>
    <tr>
       <td width="13%"><font class="NArialL">Billing Address :</font></td>
       <td width="18%"><html:textarea rows="13" name="salesOrderForm" property="billingAddress" cols="23" styleClass="txfield" disabled="true"/></td>

       <td width="15%"><font class="NArialL">Shipping Address :</font></td>
       <td width="20%">
            <html:link styleClass="NArialL" href="javascript:AddNewShippingAddress(document.salesOrderForm.shippingAddress);" onmouseover="window.status='Click to Add Shipping Address';return true" onmouseout="window.status='';return true" >Add new shipping Address</html:link>
            <br>
        <html:textarea name="salesOrderForm" rows="13" cols="23" property="shippingAddress" styleClass="txfield" disabled="true"/>
       </td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
     </tr>

     <tr><td colspan=6><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>

     <tr>
       <td width="13%"><font class="NArialL">All Freight Instructions :</font></td>
       <td width="18%">
         <html:select name="salesOrderForm" property="freightInstructionsId" styleClass="txfield" onchange="javascript:assignFreightInstructions(this);">
            <html:options collection="freightInstructions" property="value" labelProperty="label"/>
          </html:select>
       </td>
       
       <td width="15%"><font class="NArialL">All Shipping Instructions :</font></td>
       <td width="20%">
          <html:select name="salesOrderForm" property="shippingInstructionsId" styleClass="txfield" onchange="javascript:assignShippingInstructions(this);">
            <html:options collection="shippingInstructions" property="value" labelProperty="label"/>
          </html:select>
        </td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
     </tr>
     <tr>
       <td width="13%"><font class="NArialL" id="freightInstructionLabel">Freight Instructions :</font></td>
       <td width="18%"><html:textarea name="salesOrderForm" property="freightInstructions" rows="4" cols="35" styleClass="txfield" onkeydown="javascript:setTextAreaMaxLength(document.salesOrderForm.freightInstructions,300)" onkeyup="javascript:setTextAreaMaxLength(document.salesOrderForm.freightInstructions,300)" readonly="true" /></td>

       <td width="15%"><font class="NArialL" id="shippingInstructions"><bean:message key="label.sales.shippingInstructions" /></font></td>
       <td width="20%"><html:textarea name="salesOrderForm" property="shippingInstructions" rows="4" cols="35" styleClass="txfield" onkeydown="javascript:setTextAreaMaxLength(document.salesOrderForm.shippingInstructions,300)" onkeyup="javascript:setTextAreaMaxLength(document.salesOrderForm.shippingInstructions,300)" /></td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
     </tr>
     <script>setReadOnlyForFreightInsructions ( document.salesOrderForm.freightInstructionsId );</script>
     <tr>
       <td width="13%"><font class="NArialL">Comments :</font></td>
       <td width="87%" colspan="5"><html:textarea name="salesOrderForm" rows="4" property="comments" cols="100" styleClass="txfield" onkeydown="javascript:setTextAreaMaxLength(document.salesOrderForm.comments,300)" onkeyup="javascript:setTextAreaMaxLength(document.salesOrderForm.comments,300)"/></td>
     </tr>

    <tr><td colspan=4><chiptrack:internalComments commentsGroupId="AUTO"/></td></tr>
    <tr>
       <td width="13%">&nbsp;</td>
       <td width="18%">&nbsp;</td>
       <td width="15%">&nbsp;</td>
       <td width="20%">&nbsp;</td>
       <td width="22%">&nbsp;</td>
       <td width="11%">&nbsp;</td>
     </tr>
     <tr><td colspan=6><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
     <%--<tr><td colspan=6 class="NArialL"><%--chiptrack:errors styleClass="NArialL" /></td></tr>--%>

    <tr><td colspan='6' align="left" class='NArialL'><FONT id="errors" styleClass="NArialL" color='FF0000'></FONT></TD></TR>
    <tr><td colspan='6' align="left" class='NArialL'><FONT id="message" styleClass="NArialL" color='FF0000'></FONT></TD></TR>
    <tr><td colspan=6><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=5></td></tr>
     <tr><td colspan=6>

     <br>
     <font class="NArialS" color='blue'><b><li>&nbsp;Select the zero price option if you want to keep the price as zero.</b></font><br>
     <br>
     <jsp:include page="lineItemsForNewSalesOrder.jsp" flush="true" />
     </td></tr>
     <tr><td colspan=7 align=center>
    <% if((request.getParameter("isSample") != null) && (request.getParameter("isSample").equals("0"))) { %>
            <chiptrack:restrictedLink functionality='<%=Functionality.SAMPLE_NEW_SAMPLE_ORDER%>' action='<%=User.USER_ACTION_MODIFY%>' href="javascript:submitPage('SUBMIT');" onmouseover="window.status='Click here to save new sales order';return true" onmouseout="window.status='';return true">
            <img src="<%=chipTracContext%>/jsp/includes/images/submit.gif" border='0' title="Click here To Save Sales Order" ></chiptrack:restrictedLink>
    <% } else { %>
           <chiptrack:restrictedLink functionality='<%=Functionality.SALES_NEW_SALES_ORDER%>' action='<%=User.USER_ACTION_MODIFY%>' href="javascript:submitPage('SUBMIT');" onmouseover="window.status='Click here to save new sales order';return true" onmouseout="window.status='';return true">
            <img src="<%=chipTracContext%>/jsp/includes/images/submit.gif" border='0' title="Click here To Save Sales Order"></chiptrack:restrictedLink>
    <% } %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="javascript:resetForm()"><img src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border='0' onmouseover="window.status='Click  to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></a>
   </table>

<input type="hidden" name="customerName" value="<%= salesOrderForm.getCustomerName()%>" />
<input type="hidden" name="customerId" value="<%= salesOrderForm.getCustomerId()%>" />
<input type="hidden" name="shippingMethodName" value="<%= salesOrderForm.getShippingMethodName()!= null ? salesOrderForm.getShippingMethodName() : ""%>" />
<input type="hidden" name="isSample" value="<%=request.getParameter("isSample")%>">
<input type="hidden" name="action" value="">
<input type="hidden" name="shipAccount1" value="<%=request.getAttribute("Method")%>"/>

</html:form>
</html:html>
<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>
<!-- Footer starts here -->

<%@ include file="/jsp/includes/footer.jsp" %>

<!-- footer end here -->
<%
    if ( "false".equalsIgnoreCase((String)request.getAttribute("otherstateadded")) ) { %>
      	<script language="javascript">
      		addNewSalesTaxType(document.salesOrderForm.salesTaxType);
      		document.salesOrderForm.newSalesState.value = "<%=request.getAttribute("newsalesstate") %>";
      		document.salesOrderForm.newSalesTax.value = "<%=request.getAttribute("newsalesvalue") %>";
      	</script>
 <% } %>
 <script language="javascript">
 var no = <%=i%>;
 </script>
</BODY>
</HTML>